package com.wc5818.bankSearch.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wc5818.bankSearch.entity.BankReport;
import com.wc5818.bankSearch.mapper.BankReportMapper;
import com.wc5818.common.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-21
 */
@RestController
@RequestMapping("/bankSearch")
public class BankReportController {
    @Autowired
    BankReportMapper bankReportMapper;

    @GetMapping("/createNew")
    public Object createNew(String orderNum, Integer baseInfoId) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        BankReport bankReport = new BankReport();
        bankReport.setOrderNum(orderNum);
        bankReport.setBaseInfoId(baseInfoId);
        bankReport.setCreateTime(LocalDateTime.now());
        bankReport.setBankResult("1");

        if(bankReportMapper.insert(bankReport) > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(bankReport.getBankResult());
        }

        return ajaxResult;
    }

    @GetMapping("/queryByOrderNum")
    public Object queryByOrderNum(String orderNum) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = bankReportMapper.selectList(new QueryWrapper<BankReport>().eq("orderNum", orderNum));
        if(list != null && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list.get(0));
        }

        return ajaxResult;
    }



}
